HTML <figure> Tag
The <figure> tag in HTML5 is used to add self-contained content like illustrations, diagrams, photos, or codes listing in a document. It is related to the main flow, but it can be used in any position of a document and the figure goes with the flow of the document and if remove it then it should not affect the flow of the document. In simple words, the figure tag is used to semantically organize the content of images, videos, audios or even charts or tables, block of codes in the HTML document.
Syntax:
<figure>
<img src="url">
<figcaption>content</figcaption>
</figure>
Attributes: It contains mostly two tags which are given below:
Attribute Value |
Description |
---|---|
This tag is used to add an image source in the document. |
|
This tag is used to set the caption to the image. It is optional to use. |
Example: This example illustrates the use of the <figure> tag along with src, width, height & alt attributes.
HTML
<!DOCTYPE html> < html lang = "en" > < head > < meta charset = "UTF-8" /> < meta http-equiv = "X-UA-Compatible" content = "IE=edge" /> < meta name = "viewport" content = "width=device-width, initial-scale=1.0" /> < title >Document</ title > < style > figure { border: 2px solid black; padding: 5px; } </ style > </ head > < body > < figure > < img src = "https://media.w3wiki.org/wp-content/uploads/20210827151326/gfg-200x200.png" alt = "image" width = "200px" height = "200px" /> < figcaption >Geeks For Geeks</ figcaption > </ figure > </ body > </ html > |
Output: In this case the <figure> tag, it has made all the changes, as the image with caption is properly aligned with some space away from the margin. The image and caption are part of each other. The border is added to both <figure> tag and <figcaption> tag, both have occupied the border. <figure> tag is inline element.
Difference between & tags in HTML
In this article, we will learn about the <figure> & <img> tag along with its implementation. We will also learn the differences between them. Let’s begin the discussion with the figure tag in HTML.
Table of Content
- HTML <figure> Tag:
- HTML <img> Tag:
- Difference between <figure> and <img> tags:
Contact Us